/*
  This exmple program provides a trivial server program that listens for TCP
  connections on port 9995.  When they arrive, it writes a short message to
  each client connection, and closes each connection once it is flushed.

  Where possible, it exits cleanly in response to a SIGINT (ctrl-c).
*/

#include <stdlib.h>
#include <stdio.h>
#include "spserver.h"
#include "mutex.h"
#include "thread.h"
#include "fd.h"
#include <list>
#include <sys/event.h>
#include <sys/socket.h>

#ifndef WIN32
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <sys/un.h>
#include <sys/types.h>
#define MAX_EVENT_COUNT 64

#include "Session.h"
#include "NetworkObject.h"
#include "SessionList.h"
#include "SessionPool.h"
#include "Acceptor.h"
#include "IoHandler.h"


class SessionObject : public NetworkObject
{
	public:
	virtual void OnAccept() 
	{
		printf("Session Accepted\n");
	}

	virtual void OnDisconnect() 
	{
		printf("Session Disconnect\n");
	}
};

NetworkObject* CreateAcceptedObject()
{
	return new SessionObject();
}

void DestoryAcceptedObject(NetworkObject*)
{

}

	int
main ( int argc, char *argv[] )
{

	IoHandler io;
	io.Init(1, 10, CreateAcceptedObject, DestoryAcceptedObject);
	io.startListen("127.0.0.1", 9995);

	while(1)
	{
		io.Update();
		sleep(1);
	}

	getchar();

	return 0;
}				/* ----------  end of function main  ---------- */
